package com.mall.order.biz.handler;

import com.mall.order.biz.context.CreateOrderContext;
import com.mall.order.biz.context.TransHandlerContext;
import com.xiaofan.mq.order.DelayOrderProducer;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * 利用mq发送延迟取消订单消息
 * @author Javid Xi
 * @version 1.0
 * @since 2021/7/20
 */
@Component
@Slf4j
public class SendMessageHandler extends AbstractTransHandler {


	@Autowired
	DelayOrderProducer delayOrderProducer;

	@Override
	public boolean isAsync() {
		return false;
	}

	@Override
	public boolean handle(TransHandlerContext context) {
		CreateOrderContext createOrderContext = (CreateOrderContext)context;
		String orderId = createOrderContext.getOrderId();
		delayOrderProducer.sendMessage(orderId);
		return true;
	}
}